//stc8H2K08U  LCDʾ


#include <COMM/STC8H.h>					 //MCUͷļ
#include "intrins.h"					 //nopָͷļ 
#include "stdio.h"
#define uchar unsigned char                                 //ͺ궨
#define uint unsigned int                                 //ͺ궨


//TM1621d׼1/3

/*tm1621dLCDʾ-޹صLCDʾܵŻвP20 21 22  P34 35 ڸTM1621D 1621D_׼1/3*/
#define nop _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); //궨
/******************TM1621Dģ*********************/
#define SYSDIS   0x00    //ϵͳLCDƫѹ        
#define SYSEN    0x02    //ϵͳ      
#define LCDOFF   0x04    //LCDƫѹ
#define LCDON    0x06    //LCDƫѹ                                                         
#define RC       0x30    //ڲRC      
#define BIAS     0x52    //1/3ƫѹ 4       
#define WDTDIS   0x0a    //ֹŹ
#define WDTEN    0x0e    //Ź
/*ڲLCDƫѹҲʾʾLCD ؿŹ ʺ//1/3ƫѹ 4  */

/********************ƶ˿Ҫʵ**********************/
sbit CS=P3^7;
sbit WRITE=P3^6;
sbit DATA=P3^5;

/********************˵ûõTM1621Dٷ*************************/
uchar code Smg[16]={0x05,0xff,0xc7,0xE5,0x6C,0xAD,0xaf,0xE0,0xef,0xed,0xee,0x2f,0x8b,0x67,0x8f,0x8e};  //0~F
uchar code Tab0[16]={0x08,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //
/********************ʱ*************************/
void delay_nms(uint n)
{
   uint i;
   while(n--)
     for(i=0;i<500;i++);
}
/********************Ӹλд*************************/
void Write_Data_H(uchar Data, uchar Cnt)           //DataĸcntλдTM1621Dλǰ
{
uchar i;
for(i=0;i<Cnt;i++)
{
  WRITE=0;
	
  if(Data&0x80)                                   //λ
    DATA=1;               
  else
    DATA=0;
  nop;

  WRITE=1;
  nop;
  Data<<=1;
}
WRITE=0;
DATA=0;
}
/********************ӵλд*************************/
void Write_Data_L(uchar Data,uchar Cnt) //Data ĵcntλдTM1621Dλǰ
{
unsigned char i;
for(i=0;i<Cnt;i++)
{
   WRITE=0;
	        nop;
   if(Data&0x01)                                 //ӵλ
     DATA=1;  
   else
     DATA=0;
        nop;

        WRITE=1;
	         nop;
        Data>>=1;
}
  WRITE=0;
  DATA=0;  
}

/********************д*************************/
void WriteCmd(uchar Cmd)
{
CS=0;
nop;
Write_Data_H(0x80,4);     //д־100
Write_Data_H(Cmd,8);      //д
CS=1;
nop;
}

/*********ַָдݣʵд4λ************/
void WriteOneData(uchar Addr, uchar Data)
{
	
Addr=Addr<<2;
CS=0;
nop;
Write_Data_H(0xa0,3);     //дݱ־101
	
Write_Data_H(Addr,6);  //дַ
Write_Data_L(Data,4);     //д
nop;	
CS=1;
nop;
}

/*********д뷽ʽÿΪ8λдݣÿȥ************/
/*
void WriteAllData(uchar Addr,uchar *p,uchar cnt)
{
uchar i;
CS=0;
Write_Data_H(0xa0,3);          //дݱ־101
Write_Data_H(Addr<<2,6);        //дַ
for(i=0;i<cnt;i++)                //д
{
   Write_Data_L(*p,8);            
   p++;
}
CS=1;
nop;
}
*/
/*******************TM1621Dʼ**********************/
void TM1621D_init()
{
CS=1;
WRITE=1;
DATA=1;
nop;
delay_nms(1);                        
WriteCmd(BIAS);                 //1/3ƫѹ 4
WriteCmd(RC);                         //ڲRC	
WriteCmd(SYSDIS);                 //ϵͳLCDƫѹ
WriteCmd(WDTDIS);								 //ֹŹ
WriteCmd(SYSEN);                 //ϵͳ
WriteCmd(LCDON);                 //LCDƫѹ
}

/*************TM16211621DӦȫղǶԵ*****************/
void Clear1621()
{
uchar i;
for(i=0;i<32;i++) //9-21
{
WriteOneData(i, 0x00);
}
}
/*************TM1621ȫ ûȫʾвԵĵطҪӵ*****************/
/*
void quanping1621()
{
uchar i;
for(i=9;i<22;i++) //9-21
{
WriteOneData(i, 0x0f);
}
}
*/
/*tm1621dLCDʾ-޹صLCDʾܵŻвP20 21 22  P34 35 ڸTM1621D 1621D_׼1/3*/

//TM1621d׼1/3

//ʾlcd_xsbl
unsigned int lcd_xsbl=0;//lcdʾ
static void lcd_1(unsigned long xsbl_lcd)//1λλ(λ)
{
				 if(xsbl_lcd / 100 == 0)
    {
        WriteOneData(0x09,0x0b);	WriteOneData(0x0e,0x0e);  	            // 0
    }
    else if(xsbl_lcd / 100== 1)
    {
        WriteOneData(0x09,0x00);	WriteOneData(0x0e,0x06);  	            // 1
    }
    else if(xsbl_lcd / 100== 2)
    {
        WriteOneData(0x09,0x07);	WriteOneData(0x0e,0x0c);  	            // 2
    }   
    else if(xsbl_lcd / 100== 3)
    {
        WriteOneData(0x09,0x05);	WriteOneData(0x0e,0x0e);  	            // 3
    } 
    else if(xsbl_lcd / 100== 4)
    {
        WriteOneData(0x09,0x0c);	WriteOneData(0x0e,0x06);  	            // 4
    }
    else if(xsbl_lcd / 100== 5)
    {
        WriteOneData(0x09,0x0d);	WriteOneData(0x0e,0x0a);  	            // 5
    }
    else if(xsbl_lcd / 100== 6)
    {
        WriteOneData(0x09,0x0f);	WriteOneData(0x0e,0x0a);  	            // 6
    }
    else if(xsbl_lcd / 100== 7)
    {
        WriteOneData(0x09,0x00);	WriteOneData(0x0e,0x0e);                // 7
    }
    else if(xsbl_lcd / 100== 8)
    {
        WriteOneData(0x09,0x0f);	WriteOneData(0x0e,0x0e);  	            // 8
    }
    else if(xsbl_lcd / 100== 9)
    {
				WriteOneData(0x09,0x0d);	WriteOneData(0x0e,0x0e); 	      	      // 9
    }
}

static void lcd_2(unsigned long xsbl_lcd)//2λʮλ(λ)
{
				 if(xsbl_lcd % 100/10== 0)
    {
        WriteOneData(0x0c,0x0e);	WriteOneData(0x0d,0x0b);  	            // 0
    }
    else if(xsbl_lcd % 100/10== 1)
    {
        WriteOneData(0x0c,0x06);	WriteOneData(0x0d,0x00);  	            // 1
    }
    else if(xsbl_lcd % 100/10== 2)
    {
        WriteOneData(0x0c,0x0c);	WriteOneData(0x0d,0x07);  	            // 2
    }   
    else if(xsbl_lcd % 100/10== 3)
    {
        WriteOneData(0x0c,0x0e);	WriteOneData(0x0d,0x05);  	            // 3
    } 
    else if(xsbl_lcd % 100/10== 4)
    {
        WriteOneData(0x0c,0x06);	WriteOneData(0x0d,0x0c);  	            // 4
    }
    else if(xsbl_lcd % 100/10== 5)
    {
        WriteOneData(0x0c,0x0a);	WriteOneData(0x0d,0x0d);  	            // 5
    }
    else if(xsbl_lcd % 100/10== 6)
    {
        WriteOneData(0x0c,0x0a);	WriteOneData(0x0d,0x0f);  	            // 6
    }
    else if(xsbl_lcd % 100/10== 7)
    {
        WriteOneData(0x0c,0x0e);	WriteOneData(0x0d,0x00);  	            // 7
    }
    else if(xsbl_lcd % 100/10== 8)
    {
        WriteOneData(0x0c,0x0e);	WriteOneData(0x0d,0x0f);  	            // 8
    }
    else if(xsbl_lcd % 100/10== 9)
    {
        WriteOneData(0x0c,0x0e);	WriteOneData(0x0d,0x0d);  	            // 0
    }
}

static void lcd_3(unsigned long xsbl_lcd)//3λλ(λ)
{
    if(xsbl_lcd % 10 == 0)
    {
        WriteOneData(0x0a,0x0e);	WriteOneData(0x0b,0x0b);  	            // 0
    }
    else if(xsbl_lcd % 10 == 1)
    {
        WriteOneData(0x0a,0x06);	WriteOneData(0x0b,0x00);  	            // 1
    }
    else if(xsbl_lcd % 10 == 2)
    {
        WriteOneData(0x0a,0x0c);	WriteOneData(0x0b,0x07);  	            // 2
    }   
    else if(xsbl_lcd % 10 == 3)
    {
        WriteOneData(0x0a,0x0e);	WriteOneData(0x0b,0x05);  	            // 3
    } 
    else if(xsbl_lcd % 10 == 4)
    {
        WriteOneData(0x0a,0x06);	WriteOneData(0x0b,0x0c);  	            // 4
    }
    else if(xsbl_lcd % 10 == 5)
    {
        WriteOneData(0x0a,0x0a);	WriteOneData(0x0b,0x0d);  	            // 5
    }
    else if(xsbl_lcd % 10 == 6)
    {
        WriteOneData(0x0a,0x0a);	WriteOneData(0x0b,0x0f);  	            // 6
    }
    else if(xsbl_lcd % 10 == 7)
    {
        WriteOneData(0x0a,0x0e);	WriteOneData(0x0b,0x00);  	            // 7
    }
    else if(xsbl_lcd % 10 == 8)
    {
        WriteOneData(0x0a,0x0e);	WriteOneData(0x0b,0x0f);  	            // 8
    }
    else if(xsbl_lcd % 10 == 9)
    {
        WriteOneData(0x0a,0x0e);	WriteOneData(0x0b,0x0d);  	            // 0
    }
}
	
//ʾlcd_xsbl


void Delay1000ms(void)	//@11.0592MHz
{
	unsigned char data i, j, k;

	_nop_();
	_nop_();
	i = 2;
	j = 67;
	k = 183;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

//////////////////////////////////////////////////////////////////ʪģ1
#define uint32_t unsigned long
	
#define uint16_t unsigned long
#define uint8_t unsigned int

void Delay_N10us(uint32_t t)//ʱN1us
{
   while(t--)
  { 	
	_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
	_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
	_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  }
}

void SensorDelay_us(uint32_t t)//ʱ
{
		
	for(t = t-2; t>0; t--)
	{
		Delay_N10us(1);
	}
}


void Delay_4us(void)		//ʱ
{	
	Delay_N10us(1);
	Delay_N10us(1);
	Delay_N10us(1);
	Delay_N10us(1);
}

void Delay_5us(void)		//ʱ
{	
	Delay_N10us(1);
	Delay_N10us(1);
	Delay_N10us(1);
	Delay_N10us(1);
	Delay_N10us(1);

}

void Delay_1ms(uint32_t t)		//ʱ
{
   while(t--)
  {
    SensorDelay_us(1000);//////ʱ1ms
  }
}


void SCL_Pin_Output_High(void) //SCLߵƽp11
{
	P11=1;
}

void SCL_Pin_Output_Low(void) //SCL͵ƽp11
{
	P11=0;
}


void SDA_Pin_Output_High(void) //Sdaߵƽp10
{
	P10=1;
}

void SDA_Pin_Output_Low(void) //Sda͵ƽp10
{
	P10=0;
}





void SDA_Pin_IN_FLOATING(void)  //SDAΪ(׼˫)
{

    P1M0 &= ~0x01; P1M1 &= ~0x01; 
}


void Init_I2C_Sensor_Port(void) //ʼI2Cӿ,Ϊߵƽ
{	
//
//ߵƽ
	P1M0 |= 0x03; P1M1 &= ~0x03;  //10 SDA             11   SCL   
		P10=1;	//10 SDA  
		P11=1;	//11 SCL 
}




void I2C_Start(void)		 //I2CSTARTź
{
	SDA_Pin_Output_High();
	SensorDelay_us(8);
	SCL_Pin_Output_High();
	SensorDelay_us(8);
	SDA_Pin_Output_Low();
	SensorDelay_us(8);
	SCL_Pin_Output_Low();
	SensorDelay_us(8);   
}





void AHT20_WR_Byte(uint8_t Byte) //AHT21дһֽ
{
	uint8_t Data,N,i;	
	Data=Byte;
	i = 0x80;
	for(N=0;N<8;N++)
	{
		SCL_Pin_Output_Low(); 
		Delay_4us();	
		if(i&Data)
		{
			SDA_Pin_Output_High();
		}
		else
		{
			SDA_Pin_Output_Low();
		}	
			
    SCL_Pin_Output_High();
		Delay_4us();
		Data <<= 1;
		 
	}
	SCL_Pin_Output_Low();
	SensorDelay_us(8);   
	SDA_Pin_IN_FLOATING();
	SensorDelay_us(8);	
}	

uint8_t AHT20_RD_Byte(void)//AHT21ȡһֽ
{
	uint8_t Byte,i,a;
	Byte = 0;
	SCL_Pin_Output_Low();
	SDA_Pin_IN_FLOATING();
	SensorDelay_us(8);	
	for(i=0;i<8;i++)
	{
    SCL_Pin_Output_High();		
		Delay_5us();
		a=0;
		if(P10==1) a=1;
		Byte = (Byte<<1)|a;
		SCL_Pin_Output_Low();
		Delay_5us();
	}
  SDA_Pin_IN_FLOATING();
	SensorDelay_us(8);	
	return Byte;
}


uint8_t Receive_ACK(void)   //AHT21ǷлظACK
{
	uint16_t CNT;
	CNT = 0;
	SCL_Pin_Output_Low();	
	SDA_Pin_IN_FLOATING();
	SensorDelay_us(8);	
	SCL_Pin_Output_High();	
	SensorDelay_us(8);	
	while(P10==1  && CNT < 100) 
	CNT++;
	if(CNT == 100)
	{
		return 0;
	}
 	SCL_Pin_Output_Low();	
	SensorDelay_us(8);	
	return 1;
}


void Send_ACK(void)		  //ظACKź
{
	SCL_Pin_Output_Low();	
	SensorDelay_us(8);	
	SDA_Pin_Output_Low();
	SensorDelay_us(8);	
	SCL_Pin_Output_High();	
	SensorDelay_us(8);
	SCL_Pin_Output_Low();	
	SensorDelay_us(8);
	SDA_Pin_IN_FLOATING();
	SensorDelay_us(8);
}


void Send_NOT_ACK(void)	//ظACK
{
	SCL_Pin_Output_Low();	
	SensorDelay_us(8);
	SDA_Pin_Output_High();
	SensorDelay_us(8);
	SCL_Pin_Output_High();	
	SensorDelay_us(8);		
	SCL_Pin_Output_Low();	
	SensorDelay_us(8);
    SDA_Pin_Output_Low();
	SensorDelay_us(8);
	
	
	
lcd_1(147);
lcd_2(147);
lcd_3(147);
	
SensorDelay_us(500);
	
}

void Stop_I2C(void)	  //һЭ
{
	SDA_Pin_Output_Low();
	SensorDelay_us(8);
	SCL_Pin_Output_High();	
	SensorDelay_us(8);
	SDA_Pin_Output_High();
	SensorDelay_us(8);
}

uint8_t AHT20_Read_Status(void)//ȡAHT21״̬Ĵ
{

	uint8_t Byte_first;	
	I2C_Start();
	AHT20_WR_Byte(0x71);
	Receive_ACK();
	Byte_first = AHT20_RD_Byte();
	Send_NOT_ACK();
	Stop_I2C();
	return Byte_first;
}

uint8_t AHT20_Read_Cal_Enable(void)  //ѯcal enableλûʹ
{
	uint8_t val = 0;//ret = 0,
  val = AHT20_Read_Status();
	 if((val & 0x68)==0x08)
		 return 1;
   else  return 0;
 }

 
 void AHT20_SendAC(void) //AHT21AC
{

	I2C_Start();
	AHT20_WR_Byte(0x70);
	Receive_ACK();
	AHT20_WR_Byte(0xac);//0xACɼ
	Receive_ACK();
//	AHT20_WR_Byte(0x33);	//AHT20ͺŴ˴33
	AHT20_WR_Byte(0x00);	//AHT21ͺŴ˴00
	Receive_ACK();
	AHT20_WR_Byte(0x00);
	Receive_ACK();
	Stop_I2C();

}
 

//CRCУͣCRC8/MAXIM
//ʽX8+X5+X4+1
//Poly0011 0001  0x31
//λŵͱ 1000 1100 0x8c
//Cʵ룺
uint8_t Calc_CRC8(uint8_t *message,uint8_t Num)
{
        uint8_t i;
        uint8_t byte;
        uint8_t crc=0xFF;
  for(byte=0; byte<Num; byte++)
  {
    crc^=(message[byte]);
    for(i=8;i>0;--i)
    {
      if(crc&0x80) crc=(crc<<1)^0x31;
      else crc=(crc<<1);
    }
  }
        return crc;
}

 
 
void AHT20_Read_CTdata(uint32_t *ct) //ûCRCУ飬ֱӶȡAHT20¶Ⱥʪ
{
	uint8_t  Byte_1th=0;
	uint8_t  Byte_2th=0;
	uint8_t  Byte_3th=0;
	uint8_t  Byte_4th=0;
	uint8_t  Byte_5th=0;
	uint8_t  Byte_6th=0;
	uint32_t RetuData = 0;
	uint16_t cnt = 0;
	AHT20_SendAC();
	Delay_1ms(80);//ʱ80ms	
    cnt = 0;
	while(((AHT20_Read_Status()&0x80)==0x80))//ֱ״̬bit[7]Ϊ0ʾΪ״̬Ϊ1ʾæ״̬
	{
		SensorDelay_us(1508);
		if(cnt++>=100)
		{
		 break;
		 }
	}
	I2C_Start();
	AHT20_WR_Byte(0x71);
	Receive_ACK();
	Byte_1th = AHT20_RD_Byte();//״̬֣ѯ״̬Ϊ0x98,ʾΪæ״̬bit[7]Ϊ1״̬Ϊ0x1C0x0C0x08ʾΪ״̬bit[7]Ϊ0
	Send_ACK();
	Byte_2th = AHT20_RD_Byte();//ʪ
	Send_ACK();
	Byte_3th = AHT20_RD_Byte();//ʪ
	Send_ACK();
	Byte_4th = AHT20_RD_Byte();//ʪ/¶
	Send_ACK();
	Byte_5th = AHT20_RD_Byte();//¶
	Send_ACK();
	Byte_6th = AHT20_RD_Byte();//¶
	Send_NOT_ACK();
	Stop_I2C();

	RetuData = (RetuData|Byte_2th)<<8;
	RetuData = (RetuData|Byte_3th)<<8;
	RetuData = (RetuData|Byte_4th);
	RetuData =RetuData >>4;
	ct[0] = RetuData;//ʪ
	RetuData = 0;
	RetuData = (RetuData|Byte_4th)<<8;
	RetuData = (RetuData|Byte_5th)<<8;
	RetuData = (RetuData|Byte_6th);
	RetuData = RetuData&0xfffff;
	ct[1] =RetuData; //¶

}



void AHT20_Read_CTdata_crc(uint32_t *ct) //CRCУ󣬶ȡAHT20¶Ⱥʪ
{
	uint8_t  Byte_1th=0;
	uint8_t  Byte_2th=0;
	uint8_t  Byte_3th=0;
	uint8_t  Byte_4th=0;
	uint8_t  Byte_5th=0;
	uint8_t  Byte_6th=0;
	uint8_t  Byte_7th=0;
	uint32_t RetuData = 0;
	uint16_t cnt = 0;
	uint8_t  CTDATA[6]={0};//CRC
	
	AHT20_SendAC();//AHT20AC
	Delay_1ms(500);//ʱ500ms	
    cnt = 0;
	while(((AHT20_Read_Status()&0x80)==0x80))//ֱ״̬bit[7]Ϊ0ʾΪ״̬Ϊ1ʾæ״̬
	{
		SensorDelay_us(1508);
		if(cnt++>=100)
		{
		 break;
		}
	}
	
	I2C_Start();

	AHT20_WR_Byte(0x71);
	Receive_ACK();
	CTDATA[0]=Byte_1th = AHT20_RD_Byte();//״̬
	Send_ACK();
	CTDATA[1]=Byte_2th = AHT20_RD_Byte();//ʪ
	Send_ACK();
	CTDATA[2]=Byte_3th = AHT20_RD_Byte();//ʪ
	Send_ACK();
	CTDATA[3]=Byte_4th = AHT20_RD_Byte();//ʪ/¶
	Send_ACK();
	CTDATA[4]=Byte_5th = AHT20_RD_Byte();//¶
	Send_ACK();
	CTDATA[5]=Byte_6th = AHT20_RD_Byte();//¶
	Send_ACK();
	Byte_7th = AHT20_RD_Byte();//CRC
	Send_NOT_ACK();            //ע: ǷNAK
	Stop_I2C();
	
	if(Calc_CRC8(CTDATA,6)==Byte_7th)
	{
	RetuData = (RetuData|Byte_2th)<<8;
	RetuData = (RetuData|Byte_3th)<<8;
	RetuData = (RetuData|Byte_4th);
	RetuData =RetuData >>4;
	ct[0] = RetuData;//ʪ
	RetuData = 0;
	RetuData = (RetuData|Byte_4th)<<8;
	RetuData = (RetuData|Byte_5th)<<8;
	RetuData = (RetuData|Byte_6th);
	RetuData = RetuData&0xfffff;
	ct[1] =RetuData; //¶
		
	}
	else
	{
		ct[0]=0x00;
		ct[1]=0x00;//У󷵻ֵͻԸԼҪ
	}//CRC
}



void AHT20_Init(void)   //ʼAHT20
{	
	I2C_Start();
	AHT20_WR_Byte(0x70);
	Receive_ACK();
	AHT20_WR_Byte(0xbe);//0xBEʼAHT20ĳʼ0xBE
	Receive_ACK();
	AHT20_WR_Byte(0x08);//ؼĴbit[3]1ΪУ׼
	Receive_ACK();
	AHT20_WR_Byte(0x00);
	Receive_ACK();
	Stop_I2C();
	Delay_1ms(10);//ʱ10ms
}


//////////////////////////////////////////////////////////////////ʪģ1



















 
 
 

void main()
{
//////////////////////////////////////////////////////////////////ʪģ2
	 uint32_t CT_data[2];
	// volatile int  c1,t1; 
	uint32_t c1=0,t1=0,ceshi=0; 
//////////////////////////////////////////////////////////////////ʪģ2
//main
//TM1621dӦò2/3
	{
/*tm1621dLCDʾ-޹صLCDʾܵŻвP20 21 22  P34 35 ڸTM1621D 1621D_Ӧò2/3*/
    P3M0 = 0x00; P3M1 = 0x00; 
         P1M0 |= 0x03; P1M1 &= ~0x03;  //10 SDA             11   SCL   

		


TM1621D_init();                //ʼظʹѭҪĻ
delay_nms(1);
	Clear1621();//LCDԴ
	
		
		
		

		
		
//quanping1621();  //ӦÿȫʾŶ
/*tm1621dLCDʾ-޹صLCDʾܵŻвP20 21 22  P34 35 ڸTM1621D 1621D_Ӧò2/3*/
	}
	
lcd_1(888);
lcd_2(888);
lcd_3(888);
//////////////////////////////////////////////////////////////////ʪģ3
	/***********************************************************************************/
	/**///ٸϵ磬ƷоƬڲҪʱ䣬ʱ100~500ms,500ms
	/***********************************************************************************/
	Delay_1ms(500);
	/***********************************************************************************/
	/**///ϵһη0x71ȡ״̬֣ж״̬ǷΪ0x18,0x18,мĴʼ
	/***********************************************************************************/
	
	if((AHT20_Read_Status()&0x18)!=0x18)
	{
	AHT20_Init(); //³ʼĴ
	Delay_1ms(10);
	}
	
		//AHT20_Init(); //³ʼĴ
	//Delay_1ms(100);
	
	
	
	
	
	
	
	
TM1621D_init();                //ʼظʹѭҪĻ
delay_nms(1);
	Clear1621();//LCDԴ
lcd_1(123);
lcd_2(123);
lcd_3(123);
	/***********************************************************************************/
	/**///۸ݿͻԼ󷢲ȡʪݣǰwhile1ѭȡʪݣο
	/***********************************************************************************/

//////////////////////////////////////////////////////////////////ʪģ3
while(1)
{//while
	Delay1000ms();

	
P30=!P30;
//////////////////////////////////////////////////////////////////ʪģ4
		AHT20_Init(); //³ʼĴ
	Delay_1ms(10);	
	 AHT20_Read_CTdata(CT_data);       //CRCУ飬ֱӶȡAHT20¶Ⱥʪ    Ƽÿ1Sһ
    //AHT20_Read_CTdata_crc(CT_data);  //crcУ󣬶ȡAHT20¶Ⱥʪ 
	

	 c1 = CT_data[0]*100*10/1024/1024;  //õʪֵc1Ŵ10
	 t1 = CT_data[1]*200*10/1024/1024-500;//õ¶ֵt1Ŵ10
	////һͻʾݣ
//////////////////////////////////////////////////////////////////ʪģ4	
	

/*
	lcd_xsbl=lcd_xsbl+1;
	
	if (lcd_xsbl>=999)
		lcd_xsbl=0;
	

	*/
/*tm1621dLCDʾ-޹صLCDʾܵŻвP20 21 22  P34 35 ڸTM1621D 1621D_ʾ3/3*/
ceshi=ceshi+11;
lcd_1(t1);
lcd_2(t1);
lcd_3(t1);
/*tm1621dLCDʾ-޹صLCDʾܵŻвP20 21 22  P34 35 ڸTM1621D 1621D_ʾ3/3*/
	
}//while
	
}